home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat5 / varargs.z / varargs
Encoding:
Text File  |  2002-10-03  |  3.9 KB  |  88 lines

  1. VARARGS(5)                                           Last changed: 10-15-98
  2.  
  3.  
  4. NNAAMMEE
  5.      vvaarraarrggss - Variable argument list
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ""##iinncclluuddee <<vvaarraarrggss..hh>>""
  9.  
  10.      _f_u_n_c_t_i_o_n (vvaa__aalliisstt)
  11.      vvaa__ddccll
  12.      vvaa__lliisstt _p_v_a_r;
  13.      vvaa__ssttaarrtt (_p_v_a_r);
  14.      f = vvaa__aarrgg (_p_v_a_r, _t_y_p_e);
  15.      vvaa__eenndd (_p_v_a_r);
  16.  
  17. IIMMPPLLEEMMEENNTTAATTIIOONN
  18.      IRIX systems
  19.  
  20. DDEESSCCRRIIPPTTIIOONN
  21.      NOTE: vvaarraarrggss is being replaced by ssttddaarrgg(5).  See the ssttddaarrgg(5) man
  22.      page for the recommended method of passing variable argument lists.
  23.  
  24.      This set of macros provides a means of writing portable procedures
  25.      that accept variable argument lists.  Routines having variable
  26.      argument lists [such as pprriinnttff(3)] that do not use vvaarraarrggss are
  27.      inherently nonportable, because different machines use different
  28.      argument passing conventions.
  29.  
  30.      vvaa__aalliisstt is used in a function header to declare a variable argument
  31.      list.
  32.  
  33.      vvaa__ddccll is a declaration for vvaa__aalliisstt.  Note that there is no semicolon
  34.      after vvaa__ddccll.
  35.  
  36.      vvaa__lliisstt is a type which can be used for the variable _p_v_a_r, which is
  37.      used to traverse the list.  One such variable must always be declared.
  38.  
  39.      vvaa__ssttaarrtt (pvar) is called to initialize _p_v_a_r to the beginning of the
  40.      list.
  41.  
  42.      vvaa__aarrgg (_p_v_a_r, _t_y_p_e) will return the next argument in the list pointed
  43.      to by _p_v_a_r.  _T_y_p_e is the type to which the expected argument will be
  44.      converted when passed as an argument.  In standard C, arguments that
  45.      are cchhaarr or sshhoorrtt should be accessed as iinntt, ""uunnssiiggnneedd cchhaarr or
  46.      ""uunnssiiggnneedd sshhoorrtt are converted to uunnssiiggnneedd iinntt, and ffllooaatt arguments are
  47.      converted to ddoouubbllee.  Different types can be mixed, but it is up to
  48.      the routine to know what type of argument is expected, since it cannot
  49.      be determined at runtime.
  50.  
  51.      vvaa__eenndd (_p_v_a_r) is used to finish up.
  52.  
  53.      Multiple traversals, each bracketed by vvaa__ssttaarrtt ...  vvaa__eenndd,, are
  54.      possible.
  55.  
  56. EEXXAAMMPPLLEESS
  57.                ##iinncclluuddee <varargs.h>
  58.                execl(vvaa__aalliisstt)
  59.                vvaa__ddccll
  60.                {
  61.                     vvaa__lliisstt ap;
  62.                     cchhaarr *file;
  63.                     cchhaarr *args[100];
  64.                     iinntt argno = 0;
  65.  
  66.                     vvaa__ssttaarrtt(ap);
  67.                     file = vvaa__aarrgg(ap, cchhaarr *);
  68.                     wwhhiillee (args[argno++] = vvaa__aarrgg(ap, cchhaarr *))
  69.                          ;;
  70.                     vvaa__eenndd(ap);
  71.                     rreettuurrnn execv(file, args);
  72.                }
  73.  
  74. BBUUGGSS
  75.      It is up to the calling routine to determine how many arguments there
  76.      are, since it is not possible to determine this from the stack frame.
  77.      For example, eexxeeccll passes a 0 to signal the end of the list.  pprriinnttff
  78.      can tell how many arguments are supposed to be there by the format.
  79.  
  80.      The macros vvaa__ssttaarrtt and vvaa__eenndd may be arbitrarily complex; for
  81.      example, vvaa__ssttaarrtt might contain an opening brace, which is closed by a
  82.      matching brace in vvaa__eenndd.  Thus, they should only be used where they
  83.      could be placed within a single complex statement.
  84.  
  85. SSEEEE AALLSSOO
  86.      ssttddaarrgg(5)
  87.  
  88.